package com.onlinefurnitureshop.order.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.onlinefurnitureshop.customer.dao.CustomerDao;
import com.onlinefurnitureshop.customer.model.Customer;
import com.onlinefurnitureshop.customer.model.ShoppingCar;
import com.onlinefurnitureshop.order.dao.ConsigneeDao;
import com.onlinefurnitureshop.order.model.Consignee;

public class ConsigneeDaoImpl extends HibernateDaoSupport  implements ConsigneeDao {

	@Override
	public List findConsigneesByCusId(int id) {
		//Customer customer=customerDao.findCustomerByOneKey("customerId", id).get(0);
		//String queryString="select distinct con from Consignee as con where con.theCustomer='"+customer+"'";
		//List<Consignee> results = getHibernateTemplate().find(queryString);
		//return results;
		StringBuffer sb = new StringBuffer();
		sb.append("from Consignee as model ");
		sb.append(" where ");
		sb.append(" model.theCustomer="+id);
		List result=this.getHibernateTemplate().find(sb.toString());
		return result;

	}

	@Override
	public Object findConsigneeByObjId(int id) {
		String queryString="select distinct con from Consignee as con where con.objId='"+id+"'";
		List<Consignee> results = getHibernateTemplate().find(queryString);
		if(results.size()>0)
			return results.get(0);
		else
			return null;
	}

	@Override
	public void deleteConsignee(Consignee consignee) {
		getHibernateTemplate().delete(consignee);
		
	}

	@Override
	public void updateConsignee(Consignee consignee) {
		getHibernateTemplate().update(consignee);
		
	}

	@Override
	public void addConsignee(Consignee consignee) {
		getHibernateTemplate().save(consignee);		
	}
	
}
